home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / g++ / builtin.h < prev    next >
C/C++ Source or Header  |  1995-02-06  |  4KB  |  172 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1988, 1992 Free Software Foundation
  5.     written by Doug Lea (dl@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*
  21.   arithmetic, etc. functions on built in types
  22. */
  23.  
  24.  
  25. #ifndef _builtin_h
  26. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _builtin_h 1
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #include <stddef.h>
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38.  
  39. #include <std.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #include <math.h>
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #ifdef __GNUG__
  48. #define _VOLATILE_VOID volatile void
  49. #else
  50. #define _VOLATILE_VOID void
  51. #endif
  52.  
  53. typedef void (*one_arg_error_handler_t)(const char*);
  54. typedef void (*two_arg_error_handler_t)(const char*, const char*);
  55.  
  56. long         gcd(long, long);
  57. long         lg(unsigned long); 
  58. double       pow(double, long);
  59. long         pow(long, long);
  60.  
  61. extern "C" double       start_timer();
  62. extern "C" double       return_elapsed_time(double last_time = 0.0);
  63.  
  64. char*        dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
  65.  
  66. unsigned int hashpjw(const char*);
  67. unsigned int multiplicativehash(int);
  68. unsigned int foldhash(double);
  69.  
  70. extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
  71. extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
  72.  
  73. extern two_arg_error_handler_t lib_error_handler;
  74.  
  75. extern two_arg_error_handler_t 
  76.        set_lib_error_handler(two_arg_error_handler_t f);
  77.  
  78.  
  79. double abs(double arg);
  80. float abs(float arg);
  81. short abs(short arg);
  82. long abs(long arg);
  83. int sign(long arg);
  84. int sign(double arg);
  85. long sqr(long arg);
  86. double sqr(double arg);
  87. int even(long arg);
  88. int odd(long arg);
  89. long lcm(long x, long y);
  90. void (setbit)(long& x, long b);
  91. void clearbit(long& x, long b);
  92. int testbit(long x, long b);
  93.  
  94. #if !defined(IV)
  95.  
  96. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  97. inline double abs(double arg) 
  98. {
  99.   return (arg < 0.0)? -arg : arg;
  100. }
  101. #endif
  102.  
  103. inline float abs(float arg) 
  104. {
  105.   return (arg < 0.0)? -arg : arg;
  106. }
  107.  
  108. inline short abs(short arg) 
  109. {
  110.   return (arg < 0)? -arg : arg;
  111. }
  112.  
  113. inline long abs(long arg) 
  114. {
  115.   return (arg < 0)? -arg : arg;
  116. }
  117.  
  118. inline int sign(long arg)
  119. {
  120.   return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
  121. }
  122.  
  123. inline int sign(double arg)
  124. {
  125.   return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
  126. }
  127.  
  128. inline long sqr(long arg)
  129. {
  130.   return arg * arg;
  131. }
  132.  
  133. #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
  134. inline double sqr(double arg)
  135. {
  136.   return arg * arg;
  137. }
  138. #endif
  139.  
  140. inline int even(long arg)
  141. {
  142.   return !(arg & 1);
  143. }
  144.  
  145. inline int odd(long arg)
  146. {
  147.   return (arg & 1);
  148. }
  149.  
  150. inline long lcm(long x, long y)
  151. {
  152.   return x / gcd(x, y) * y;
  153. }
  154.  
  155. inline void (setbit)(long& x, long b)
  156. {
  157.   x |= (1 << b);
  158. }
  159.  
  160. inline void clearbit(long& x, long b)
  161. {
  162.   x &= ~(1 << b);
  163. }
  164.  
  165. inline int testbit(long x, long b)
  166. {
  167.   return ((x & (1 << b)) != 0);
  168. }
  169.  
  170. #endif
  171. #endif
  172.